<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('销售列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="role-form">
                <div class="select-list">
                    <ul>
                        <li>
                            销售名称：<input type="text" name="sName"/>
                        </li>
                        <li>
                        处理人:<select name="uId" id="uId">
                        <option value="">请选择处理人</option>
                    </select>
                    </li>

                        <li>
                            客户:<select name="cId" id="cId">
                            <option value="">请选择客户</option>
                        </select>
                        </li>
                        <li class="select-time">
                            <label>销售时间： </label>
                            <input type="text" class="time-input"  name="startTime" placeholder="开始时间" value=""/>
                            <span>-</span>
                            <input type="text" class="time-input" name="endTime" placeholder="结束时间" value=""/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:role:add">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:role:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:role:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:role:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:role:remove')}]];
    var prefix = ctx + "cms/sale";

    function addUserOptions(project) {

        var pro = $('#uId');
        var options="";
        $(project).each(function() {
            options += '<option  value="' + this.userId + '" >' + this.userName + '</option>';
        });
        pro.append(options);
    }

    $(function () {
        $.ajax({
            url: prefix+"/userList",//请求地址
            type:"get" ,// 请求方式
            async:false,// 同步异步   默认true  异步
            data:{},//请求的附加数据
            timeout:1000,//请求超时时间  单位毫秒  当超时会调用error方法
            dataType:"json",//
            success:function(data){ //请求成功的回调方法
                console.log(data);
                if (data!== null) {
                    var project = data.data;
                    console.log(project)
                    addUserOptions(project);

                }
            },
            error:function(){
                console.log("ajax中error 方法");
            },
            complete:function(){ //当前完成就会调用  不论成功 失败
                console.log("complete 方法");
            }
        });
    })


    function addClientOptions(project) {

        var pro = $('#cId');
        var options="";
        $(project).each(function() {
            options += '<option  value="' + this.cid + '" >' + this.cname + '</option>';
        });
        pro.append(options);
    }

    $(function () {
        $.ajax({
            url: prefix+"/clientList",//请求地址
            type:"get" ,// 请求方式
            async:false,// 同步异步   默认true  异步
            data:{},//请求的附加数据
            timeout:1000,//请求超时时间  单位毫秒  当超时会调用error方法
            dataType:"json",//
            success:function(data){ //请求成功的回调方法
                console.log(data);
                if (data!== null) {
                    var project = data.data;
                    console.log(project)
                    addClientOptions(project);

                }
            },
            error:function(){
                console.log("ajax中error 方法");
            },
            complete:function(){ //当前完成就会调用  不论成功 失败
                console.log("complete 方法");
            }
        });
    })

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            modalName: "销售",
            columns: [{
                checkbox: true
            },
                {
                    field: 'sId',
                    title: '销售订单编号'
                },
                {
                    field: 'sName',
                    title: '销售名称',
                    sortable: true
                },
                {
                    field: 'userName',
                    title: '处理人',
                    sortable: true
                },
                {
                    field: 'cname',
                    title: '客户名称',
                    sortable: true
                },
                {
                    field: 'phone',
                    title: '客户电话',
                    sortable: true
                },
                {
                    field: 'address',
                    title: '客户地址',
                    sortable: true
                },
                {
                    field: 'saleTime',
                    title: '销售时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.sId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.sId + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });





</script>
</body>
</html>